drop database cdcachemyisam_mit_pk_mit_ref_mit_index_mit_partitionierung;
create database cdcachemyisam_mit_pk_mit_ref_mit_index_mit_partitionierung;
use cdcachemyisam_mit_pk_mit_ref_mit_index_mit_partitionierung;

/*==============================================================*/
/* Datenbank mit PK, Ref, Index und Partitionierung             */
/*==============================================================*/

/*==============================================================*/
/* Table: Artists                                               */
/*==============================================================*/
create table artists
(
   artistId             int not null auto_increment,
   name                 varchar(255) not null,
   primary key (artistId)
)
ENGINE = MYISAM
PARTITION BY KEY(artistId)
PARTITIONS 5;

/*==============================================================*/
/* Index: artist_name						*/
/*==============================================================*/
create index artist_name USING BTREE on artists
(
	name
);

/*==============================================================*/
/* Table: cds                                                   */
/*==============================================================*/
create table cds
(
   cddbId               bigint not null,
   artistId             int not null REFERENCES artists(artistId),
   title                varchar(255) not null,
   version              int not null,
   numTracks            int not null,
   extd                 text,
   disclen              int not null,
   year                 char(4),
   genreId		int not null REFERENCES genres(genreId),
   primary key (cddbId)
)
ENGINE = MYISAM
PARTITION BY KEY(cddbId)
PARTITIONS 5;

/*==============================================================*/
/* Index: cds_artistId						*/
/*==============================================================*/
create index cds_artistID USING BTREE on cds
(
	artistId
);

/*==============================================================*/
/* Index: cds_title						*/
/*==============================================================*/
create index cds_title USING BTREE on cds
(
	title
);

/*==============================================================*/
/* Index: _WA_Sys_disclen_5070F446                              */
/*==============================================================*/
create index _WA_Sys_disclen_5070F446 USING BTREE on cds
(
   disclen
);

/*==============================================================*/
/* Index: _WA_Sys_numTracks_5070F446                            */
/*==============================================================*/
create index _WA_Sys_numTracks_5070F446 USING BTREE on cds
(
   numTracks
);

/*==============================================================*/
/* Index: _WA_Sys_version_5070F446                              */
/*==============================================================*/
create index _WA_Sys_version_5070F446 USING BTREE on cds
(
   version
);


/*==============================================================*/
/* Index: Genre_Index                                 */
/*==============================================================*/
create index _WA_Sys_year_5070F446 USING BTREE on cds
(
   year
);

/*==============================================================*/
/* Index: genre_Index                                 */
/*==============================================================*/
create index genre_index USING BTREE on cds
(
   genreId
);

/*==============================================================*/
/* Index: cds_stat                                              */
/*==============================================================*/
create index cds_stat USING BTREE on cds
(
   cddbId,
   artistId,
   title,
   version,
   numTracks,
   year,
   genreId
);

/*==============================================================*/
/* Table: genres                                                */
/*==============================================================*/
create table genres
(
   genreId              int not null,
   genre                varchar(255),
   primary key (genreId)
)
ENGINE = MYISAM
PARTITION BY KEY(genreId)
PARTITIONS 5;

/*==============================================================*/
/* Index: genres_genre						*/
/*==============================================================*/
create index genres_genre USING BTREE on genres
(
	genre
);

/*==============================================================*/
/* Table: tracks                                                */
/*==============================================================*/
create table tracks
(
   cddbId               bigint not null REFERENCES cds(cddbId),
   trackNo              int not null,
   offset               int not null,
   title                varchar(255) not null,
   artistId             int REFERENCES artists(artistId),
   extt                 text,
   primary key (cddbId, trackNo)
)
ENGINE = MYISAM
PARTITION BY KEY(cddbId, trackNo) 
PARTITIONS 5;

/*==============================================================*/
/* Index: tracks_cddbId						*/
/*==============================================================*/
create index tracks_cddbId USING BTREE on tracks
(
	cddbId
);

/*==============================================================*/
/* Index: _WA_Sys_artistId_00551192                             */
/*==============================================================*/
create index _WA_Sys_artistId_00551192 USING BTREE on tracks
(
   artistId
);

/*==============================================================*/
/* Index: _WA_Sys_offset_00551192                               */
/*==============================================================*/
create index _WA_Sys_offset_00551192 USING BTREE on tracks
(
   offset
);

/*==============================================================*/
/* Index: _WA_Sys_title_00551192                                */
/*==============================================================*/
create index _WA_Sys_title_00551192 USING BTREE on tracks
(
   title
);

/*==============================================================*/
/* Index: _WA_Sys_trackNo_00551192                              */
/*==============================================================*/
create index _WA_Sys_trackNo_00551192 USING BTREE on tracks
(
   trackNo
);
